package leetcode_2501_2600;

import mess.AddTwoNumbers;

import java.util.*;

public class LeeCode_2593 {
    public static void main(String[] args) {

    }
    private static long findScore(int[] nums) {
        int n = nums.length;
        long ans = 0;
        TreeMap<Integer, List<Integer>> map = new TreeMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(nums[i])){
                map.get(nums[i]).add(i);
            }else {
                List<Integer> list = new ArrayList<>();
                list.add(i);
                map.put(nums[i], list);
            }
        }
        Set<Integer> used = new HashSet<>();
        for (Integer key : map.keySet()) {
            List<Integer> list = map.get(key);
            for (Integer index : list) {
                if (used.contains(index)){
                    continue;
                }
                ans += nums[index];
                if (index - 1 >= 0)
                    used.add(index - 1);
                if (index + 1 < n)
                    used.add(index + 1);
            }
        }
        return ans;
    }
}
